<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="<?php echo __PUBLIC__?>/Admin/Bootstrap/Css/bootstrap.min.css" />
    <script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>


    <style type="text/css">
        body{
            margin-bottom: 100px;
        }
        .table th, .table td{
            vertical-align: middle;
        }
    </style>
    <!-- 异步判断货品是否存在 -->
    <script type="text/javascript">
        $(function(){
            var sel=$('select[name="combine[]"]');
            var len=sel.length;
            var gid=$('input[name="goods_gid"]').val();
            sel.change(function(){
                var remote={
                    'gid':gid,
                    'combine':'',
                }
                for (var i = 0; i < len; i++) {
                    if(sel.eq(i).val() == 0){
                        return;
                    }else{
                        var x = sel.eq(i).val();
                        remote.combine += x+"|";
                    }
                };
                // console.log(remote);
                $.ajax({
                    url: '<?php echo U('ajaxList')?>',
                    type: 'POST',
                    dataType: 'json',
                    data: {remote: remote},
                    success:function(data){
                        // console.log(data);
                        // 判断返回值
                        if(data==0){
                            alert('货品已存在，如果要修改库存，请点击修改');
                            for (var i = 0; i < len; i++){
                                sel.eq(i).val(0);
                            }
                        }
                        alert(old);
                        alert(oldnum);
                    }
                })
                
            })
        })
    </script>
</head>
<body>
    <div class="alert alert-success">编辑货品列表</div>
    <div class="container-fluid" style="padding:0;">
    <div class="row-fluid">
    <div class="span12">

    
    <form action="" method='post'>
    
        <table class='table table-bordered table-hover'>
            <tr>
                <th></th>
                <?php foreach ($typeData as $k=>$v){?>
                    <th><?php echo $k?></th>
                <?php }?>
                <th>库存</th>
                <th>货号</th>
            </tr>

            <tr class="info">
                <td>编辑货品</td>
                <?php foreach ($typeData as $k=>$v){?>
                <td>
                    <select name="combine[]" style="width:200px;" >
                        <option value="0">-请选择-</option>
                           <?php foreach ($v as $kk=>$vv){?>
                            <option value="<?php echo $vv['gaid']?>" <?php if(in_array($vv['gaid'],$arr['combine'])){?>
                 selected="selected" 
               <?php }?>><?php echo $vv['gavalue']?></option>
                            <?php }?>
                    </select>
                </td>
                <?php }?>
                <td>
                    <input type="text" name='glstock' style="width:150px;" required="" value="<?php echo $arr['glstock']?>" />
                </td>
                <td>
                    <input type="text" name='glnumber'  style="width:150px;" required="" value="<?php echo $arr['glnumber']?>" />
                </td>
            </tr>
            
        </table>
        <input type="hidden" name="glid" value="<?php echo $arr['glid']?>" />
        <input type="hidden" name="goods_gid" value="<?php echo $gid?>" />
        <input type="submit" value='提交编辑' class="btn btn-primary"/>
    </form>


    </div>
    </div>
    </div>

</body>
</html>